<template>
  <div class="box">
    <div class="code">
      <!--      <p class="title">扫码登录</p>-->
      <p class="title">用户名登录</p>
      <!--      <span class="explain">请使用微信扫码登录</span>-->
      <span class="explain">请使用用户名密码登录</span>
      <!--      <img class="codeImg" src="../../assets/1.jpg" alt=""/>-->
      <div class="peopleImg">
        <el-input v-model="user" class="userItem" placeholder="用户名"/>
        <el-input v-model="password" class="userItem" show-password placeholder="密码"/>
        <el-button type="primary" class="userItem" @click="login()">登录</el-button>
      </div>
      <div class="other">
        <div class="border"></div>
        <span style="font-size: 14px; margin: 0 10px; color: #707689"
        >其他登录方式</span
        >
        <div class="border"></div>
      </div>
      <div class="otherImg" @click="goIndex()">
        <el-icon>
          <Avatar/>
        </el-icon>
      </div>
    </div>
  </div>
</template>

<script setup>
import {useRouter} from "vue-router";
import {ref} from "vue";
import Api from '../../api/index.ts'
import {ElMessage} from "element-plus";

const router = useRouter();
const goIndex = () => {
  router.push("/index");
};

// 用户名登录
const user = ref('19935637043')
const password = ref('123456')
const login = () => {
  Api.login(user.value, password.value).then(res => {
    if (res.code === 1) {
      ElMessage({
        message: '登录成功',
        type: 'success',
      })
      localStorage.setItem('token', res.data.token);
      Api.getUserInfo().then((res) => {
        localStorage.setItem('userInfo', JSON.stringify(res.data));
      })
      router.push('/index')
    }

  })
}
</script>

<style scoped lang="less">
.box {
  box-sizing: border-box;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  background-image: url("../../assets/loginBack.png");
}

.code {
  box-sizing: border-box;
  margin-left: 56vw;
  width: 23vw;
  height: 60vh;
  padding: 45px 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.3);

  .title {
    font-size: 20px;
    margin: 0;
    color: #373c4d;
  }

  .explain {
    margin-top: 8px;
    font-size: 14px;
    margin-bottom: 29px;
    color: #767b8d;
  }

  .codeImg {
    width: 210px;
    height: 210px;
  }

  .peopleImg {
    width: 350px;
    height: 210px;
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;

    .userItem {
      width: 260px;
      height: 40px;
    }
  }

  .other {
    margin-top: 37px;
    color: #848899;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;

    .border {
      width: 115px;
      border: 1px solid #eeeff0;
      margin: 0;
    }
  }

  .otherImg {
    width: 38px;
    height: 38px;
    line-height: 38px;
    text-align: center;
    font-size: 30px;
    color: #fff;
    border-radius: 5px;
    border: 1px solid #409eff;
    background-color: #409eff;
  }
}
</style>
